package cn.qw.controller;

import cn.qw.dao.DepartmentMapper;
import cn.qw.dao.EmployeeMapper;
import cn.qw.pojo.Department;
import cn.qw.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DeptController {

    @Autowired
    private DepartmentMapper departmentMapper;
    @Autowired
    private EmployeeMapper employeeMapper;

    @GetMapping("/dept/{id}")
    public Department getDept(@PathVariable("id") Integer id) {
        return departmentMapper.selectByPrimaryKey(id);
    }

    @GetMapping("/dept")
    public Department save(Department department) {
        departmentMapper.insert(department);
        return department;
    }


    @GetMapping("/emp/{id}")
    public Employee getEmp(@PathVariable("id") Integer  id) {
        return employeeMapper.selectByPrimaryKey(id);
    }
}
